import { defineStore } from "pinia";
import {
    getCategory1,
    getCategory2,
    getCategory3,
    getAttr,
} from "@/api/acl/product/index";
import type { getCategoryType,attrType } from "@/api/acl/product/type";
import type { category1 } from "../type";

export const getCategory = defineStore("category", {
    state: (): category1 => {
        return {
            // 一级
            cateGory1: [],
            cfId: "",
            // 二级
            cateGory2: [],
            csId: "",
            // 三级
            cateGory3: [],
            ctId: "",
        };
    },
    actions: {
        async getCategory1() {
            let result: getCategoryType = await getCategory1();
            if (result.code == 200) {
                this.cateGory1 = result.data;
            }
        },

        async getCategory2() {
            let result: getCategoryType = await getCategory2(this.cfId);
            if (result.code == 200) {
                this.cateGory2 = result.data;
            }
        },
        async getCategory3() {
            let result: getCategoryType = await getCategory3(this.csId);
            if (result.code == 200) {
                this.cateGory3 = result.data;
            }
        },

    },
});
